<template>
  <div class="sports-matches">
    <h2>赛事安排</h2>
    
    <div class="tabs">
      <button 
        @click="activeTab = 'upcoming'" 
        :class="{ active: activeTab === 'upcoming' }"
        class="tab-button"
      >
        即将进行
      </button>
      <button 
        @click="activeTab = 'completed'" 
        :class="{ active: activeTab === 'completed' }"
        class="tab-button"
      >
        已结束
      </button>
    </div>

    <div class="matches-container">
      <div v-if="activeTab === 'upcoming'" class="matches-list">
        <div v-for="match in upcomingMatches" :key="match.id" class="match-card upcoming">
          <div class="match-header">
            <span class="match-sport">{{ match.sport }}</span>
            <span class="match-time">{{ formatMatchTime(match.time) }}</span>
          </div>
          <div class="match-teams">
            <div class="team">
              <img :src="match.homeTeam.logo" :alt="match.homeTeam.name" class="team-logo" />
              <span class="team-name">{{ match.homeTeam.name }}</span>
            </div>
            <div class="match-info">
              <span class="vs">VS</span>
              <span class="match-venue">{{ match.venue }}</span>
            </div>
            <div class="team">
              <img :src="match.awayTeam.logo" :alt="match.awayTeam.name" class="team-logo" />
              <span class="team-name">{{ match.awayTeam.name }}</span>
            </div>
          </div>
        </div>
      </div>

      <div v-if="activeTab === 'completed'" class="matches-list">
        <div v-for="match in completedMatches" :key="match.id" class="match-card completed">
          <div class="match-header">
            <span class="match-sport">{{ match.sport }}</span>
            <span class="match-time">{{ formatMatchTime(match.time) }}</span>
          </div>
          <div class="match-teams">
            <div class="team" :class="{ winner: match.homeTeam.score > match.awayTeam.score }">
              <img :src="match.homeTeam.logo" :alt="match.homeTeam.name" class="team-logo" />
              <span class="team-name">{{ match.homeTeam.name }}</span>
              <span class="team-score">{{ match.homeTeam.score }}</span>
            </div>
            <div class="match-info">
              <span class="final-score">比赛结束</span>
              <span class="match-status">{{ match.status }}</span>
            </div>
            <div class="team" :class="{ winner: match.awayTeam.score > match.homeTeam.score }">
              <img :src="match.awayTeam.logo" :alt="match.awayTeam.name" class="team-logo" />
              <span class="team-name">{{ match.awayTeam.name }}</span>
              <span class="team-score">{{ match.awayTeam.score }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const activeTab = ref('upcoming')

const upcomingMatches = ref([
  {
    id: 1,
    sport: '足球',
    time: new Date('2024-10-25T20:00:00'),
    homeTeam: {
      name: '中国国家队',
      logo: 'https://picsum.photos/seed/china/60/60.jpg'
    },
    awayTeam: {
      name: '韩国国家队',
      logo: 'https://picsum.photos/seed/korea/60/60.jpg'
    },
    venue: '北京工人体育场'
  },
  {
    id: 2,
    sport: '篮球',
    time: new Date('2024-10-25T19:30:00'),
    homeTeam: {
      name: '洛杉矶湖人',
      logo: 'https://picsum.photos/seed/lakers/60/60.jpg'
    },
    awayTeam: {
      name: '金州勇士',
      logo: 'https://picsum.photos/seed/warriors/60/60.jpg'
    },
    venue: '斯台普斯中心'
  },
  {
    id: 3,
    sport: '网球',
    time: new Date('2024-10-26T14:00:00'),
    homeTeam: {
      name: '德约科维奇',
      logo: 'https://picsum.photos/seed/djokovic/60/60.jpg'
    },
    awayTeam: {
      name: '纳达尔',
      logo: 'https://picsum.photos/seed/nadal/60/60.jpg'
    },
    venue: '温布尔登球场'
  }
])

const completedMatches = ref([
  {
    id: 4,
    sport: '足球',
    time: new Date('2024-10-23T22:00:00'),
    homeTeam: {
      name: '皇家马德里',
      logo: 'https://picsum.photos/seed/real-madrid/60/60.jpg',
      score: 2
    },
    awayTeam: {
      name: '巴塞罗那',
      logo: 'https://picsum.photos/seed/barcelona/60/60.jpg',
      score: 1
    },
    status: '全场结束',
    venue: '伯纳乌球场'
  },
  {
    id: 5,
    sport: '篮球',
    time: new Date('2024-10-23T10:00:00'),
    homeTeam: {
      name: '波士顿凯尔特人',
      logo: 'https://picsum.photos/seed/celtics/60/60.jpg',
      score: 108
    },
    awayTeam: {
      name: '迈阿密热火',
      logo: 'https://picsum.photos/seed/heat/60/60.jpg',
      score: 102
    },
    status: '全场结束',
    venue: 'TD花园球馆'
  }
])

const formatMatchTime = (time) => {
  const options = { 
    month: '2-digit', 
    day: '2-digit', 
    hour: '2-digit', 
    minute: '2-digit',
    weekday: 'short'
  }
  return time.toLocaleString('zh-CN', options)
}
</script>

<style scoped>
.sports-matches {
  padding: 20px;
}

.sports-matches h2 {
  font-size: 1.8rem;
  color: #2c3e50;
  margin-bottom: 20px;
  border-left: 4px solid #e74c3c;
  padding-left: 15px;
}

.tabs {
  display: flex;
  margin-bottom: 20px;
  border-bottom: 2px solid #ecf0f1;
}

.tab-button {
  padding: 12px 24px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
  color: #7f8c8d;
  border-bottom: 3px solid transparent;
  transition: all 0.3s ease;
}

.tab-button.active {
  color: #e74c3c;
  border-bottom-color: #e74c3c;
  font-weight: 600;
}

.matches-container {
  min-height: 400px;
}

.matches-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.match-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.match-card:hover {
  transform: translateY(-2px);
}

.match-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.match-sport {
  background: #e74c3c;
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
}

.match-time {
  color: #7f8c8d;
  font-size: 0.9rem;
}

.match-teams {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.team {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  transition: background-color 0.3s ease;
}

.team.winner {
  background-color: #d4edda;
}

.team-logo {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  margin-bottom: 10px;
  object-fit: cover;
}

.team-name {
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 5px;
  font-size: 0.9rem;
}

.team-score {
  font-size: 1.5rem;
  font-weight: bold;
  color: #e74c3c;
}

.match-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 20px;
}

.vs {
  font-weight: bold;
  color: #e74c3c;
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.match-venue {
  color: #7f8c8d;
  font-size: 0.8rem;
  text-align: center;
}

.final-score {
  font-weight: 600;
  color: #27ae60;
  margin-bottom: 5px;
}

.match-status {
  color: #7f8c8d;
  font-size: 0.8rem;
}

@media (max-width: 768px) {
  .sports-matches {
    padding: 15px;
  }
  
  .match-teams {
    flex-direction: column;
    gap: 15px;
  }
  
  .match-info {
    padding: 10px 0;
  }
  
  .team {
    flex-direction: row;
    justify-content: center;
    gap: 15px;
  }
  
  .team-logo {
    width: 50px;
    height: 50px;
    margin-bottom: 0;
  }
}
</style>